#-*- coding:UTF-8 -*-
__author__ = 'Frank Yang <frankyang418@gmail.com>'
__date__ = "13-5-16 上午10:24"
__doc__ = u""

from lib.vendor.session import Session, RedisSession
from etc.appconf import USE_REDIS


class SessionMixin(object):
    @property
    def session(self):
        if not hasattr(self, '_session'):
            if USE_REDIS:
                sid = self.get_secure_cookie('sessionid')
                self._session = RedisSession(self.application.redis, sid)
                if not sid:
                    self.set_secure_cookie('sessionid', self._session.id, expires_days=None)
            else:
                self._session = Session(self.get_secure_cookie, self.set_secure_cookie)
        return self._session